package org.open.cobertura.util;

import org.open.cobertura.logging.CoberturaConsoleHandler;

import java.io.InputStream;
import java.util.logging.LogManager;
import java.util.logging.Logger;

public class LoggingUtil {
    private final static Logger logger = Logger.getLogger(LoggingUtil.class.getName());

    /**
     * 设置日志格式
     */
    public static void setLogging(){
        logger.addHandler(new CoberturaConsoleHandler());
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        try (InputStream inputStream = classLoader.getResourceAsStream("OpenCobertura.properties")) {
            if (inputStream != null) {
                LogManager.getLogManager().readConfiguration(inputStream);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("读取log配置文件异常");
        }
    }

    /**
     * 打印banner
     */
    public static void printBanner(){
        System.out.println("");
        System.out.println(" _____  ____  ____  _  _  ___  _____  ____  ____  ____  ____  __  __  ____    __");
        System.out.println("(  _  )(  _ \\( ___)( \\( )/ __)(  _  )(  _ \\( ___)(  _ \\(_  _)(  )(  )(  _ \\  /__\\");
        System.out.println(" )(_)(  )___/ )__)  )  (( (__  )(_)(  ) _ < )__)  )   /  )(   )(__)(  )   / /(__)\\");
        System.out.println("(_____)(__)  (____)(_)\\_)\\___)(_____)(____/(____)(_)\\_) (__) (______)(_)\\_)(__)(__)");
        System.out.println("");
        System.out.println("");
    }
}
